import time
import unittest
from unittest import TestCase

from appium import webdriver
import pytest
import yaml

from Pages.AntForestPages.MyslPage import MyslPage
from Pages.AntForestPages.zfbHomePage import ZfbHomePage
from Pages.AntForestPages.zfbLoginPage import ZfbLoginPage
from Pages.AntForestPages.DoubleClickPage import ZfbDoubleClick
from common.data_util import readYaml
from common.path import yamlPath


class TestShou:

    def setup_class(self):
        print('setup')
        capss = {
            "deviceName": "0000",
            "platformName": "Android",
            "appPackage": "com.eg.android.AlipayGphone",
            "appActivity": "com.eg.android.AlipayGphone.AlipayLogin",
            "newCommandTimeout": 6000,
            "noReset": True
        }
        path = yamlPath()
        print(path)
        data = readYaml(path)
        caps = data["caps"]
        print(capss)
        print(caps)

        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', capss)

    # @pytest.mark.run(order=2)  # 第二个执行
    def test_login(self):
        denglu = ZfbLoginPage(driver=self.driver)
        home = ZfbHomePage(driver=self.driver)
        dddian = MyslPage(driver=self.driver)
        doublecard = ZfbDoubleClick(driver=self.driver)

        denglu.loginPage_mysl()
        home.homePage_myslIc()
        a = dddian.todayEnergy()
        print(a)
        dddian.yijianshou_zj()
        # doublecard.DC_beibaoIc()  # 使用双击卡
        dddian.findEnergy()
        dddian.yijianshou_bieren()
        b = dddian.todayEnergy()
        print('本次收了{}g能量，今日收了{}g能量'.format(str(b-a), str(b)))

        print(b-a)


if __name__ == '__main__':
    pytest.main()  # -s   -v

    # pytest.main(['-vs', '-n=2', '--reruns=2'])

    # pytest -vs --reruns 2  # 2个线程执行用例  失败用例执行两次
    # 命令行执行不用带'='  --reruns  2


# -s:表示输出调试信息，包括print打印的信息
# -V:显示更详细的信息
# -vs:这两个参数一起用
# -n:支持多线程或青分布式运行测试用例。如:pytest -vs ./testcase/test login.py -n 2--reruns NUM:失败用例重跑
# -x:表示只要要一个用例报错，那么测试停止。--maxfail=2 出现两个用例失败就停止。-
# k:根据测试用例的部分字符串指定测试用例。如: pytest -vs ./testcase -k "ao'

